package klk.shop.objects;

import java.util.Date;

import klk.shop.utilities.KCreditCardValidator;

/**
 * Die Klasse, um eine Kreditkarte darzustellen.
 * -eine Kreditkartennummernfeld
 * -ein Ablaufdatum
 * @version 1.0
 * @author kev
 * @since JDK 1.4
 */
public class CreditCard extends KLKObject{
	
	protected String cardNumber;
	protected Date expirationDate;
	
	public String getCardNumber() {
		return cardNumber;
	}
	public void setCardNumber(String cardNumber) {
		this.cardNumber = cardNumber;
	}
	
	public Date getExpirationDate() {
		return expirationDate;
	}
	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}
	
	public CreditCard(String number, Date expirationDate) {
		super();
		this.cardNumber = number;
		this.expirationDate = expirationDate;
	}
	public CreditCard() {
		this("", new Date());
	}
	
	
	@SuppressWarnings("deprecation")
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		String shortenedCardNumber=cardNumber.substring(0, cardNumber.length()-3)+"***";
		sb.append(shortenedCardNumber);
		sb.append(" (");
		sb.append(KCreditCardValidator.getBankName(cardNumber));
		sb.append(", ");
		sb.append((expirationDate.getMonth()+1));
		sb.append('/');
		sb.append((expirationDate.getYear()+1900));
		sb.append(")");
		return sb.toString();
	}
	
	@Override
	public String toHtml() {
		return toString();
	}
	
}
